package com.yochi.pictureseditor.effects.effectsimpl;

import com.yochi.pictureseditor.effects.EffectParametrized;
import com.yochi.pictureseditor.exceptions.NullImageException;
import com.yochi.pictureseditor.images.Image;
import com.yochi.pictureseditor.images.ImageImpl;

public class EffectAddNoize extends EffectParametrized {
	
	  //////////////////
	 // CONSTRUCTORS //
	//////////////////
	
	public EffectAddNoize(Image img) {
		super(img, "Noize quantity (%)", 0, 100);
		setPreParametrized(false);
	}
	
	public EffectAddNoize(Image img, int param) {
		super(img, "Noize quantity (%)", 0, 100);
		this.getParameter().setValue(param);
		setPreParametrized(true);
	}
	
	
	  ////////////
	 // NATIVE //
	////////////
	
	static {
		System.loadLibrary("pictureseditor");
	}
	
	public native ImageImpl process(Image image, int parameter);
	
	
	  ////////////
	 // PUBLIC //
	////////////

	@Override
	public Image apply() throws NullImageException {
		if(getImage()==null) throw new NullImageException("load an image before applying effect");
		Image result = process();
		setResult(result);
		return result;
	}
	
	  ///////////////
	 // PROTECTED //
	///////////////
	
	@Override
	protected Image process() {
		return process(getImage(), Double.valueOf(getParameter().getValue()).intValue());
	}
	
	@Override
	public String toString() {
		return "[EffectAddNoize]";
	}

}
